package com.tz.farmer.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tz.farmer.model.FarmerUserInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @ClassName SmartAdminUserInfoMapper
 * @Description TODO
 * @Creator kaikai
 * @Date 2021/5/11
 */

public interface FarmerUserInfoMapper extends BaseMapper<FarmerUserInfo> {

    @Select("<script>select unisc_id as label,business_name as value from business_info b " +
            " where b.is_delete=0  " +
            " <if test = \"businessCode != null   \"  > and b.unisc_id = #{businessCode} </if> \n" +
            " <if test = \"city != null   \"  > and b.city = #{city} </if> \n" +
            "</script>")
    List<Map<String,Object>> businessSelect(@Param("businessCode") String businessCode,@Param("city") String city);


    @Select("select b.fun_id from farmer_user_info a left join role_permission_info b on a.role_id=b.role_Id where a.id=#{id} ")

    List<String> selectFunByUser(Integer id);
    @Select("select b.id from farmer_user_info f ,business_info b   where b.is_delete =0 and f.business=b.unisc_id and f.user_account =#{userAccount}")
    Integer selectAusinessByAccount(@Param("userAccount") String userAccount);

    @Select("select b.is_delete from farmer_user_info f ,business_info b   where b.is_delete =0 and f.business=b.unisc_id and f.user_account =#{userAccount}")
    int selectAusinessByAccountIsDelete(String userAccount);

    @Select("select password from farmer_user_info f where f.user_account =#{userAccount}")
    String selectPasswordByUserAccount(@Param("userAccount") String userAccount);

    @Update("update farmer_user_info set password=#{newPassword}  where user_account =#{userAccount}")
    void editPassword(@Param("newPassword") String newPassword,@Param("userAccount") String userAccount);

    @Select("select r.role_name from farmer_role_info r inner join farmer_user_info f on r.id = f.role_id where f.user_account =#{userAccount}")
    String selectRoleNameByAccount(@Param("userAccount") String userAccount);

    @Select("select business from  farmer_user_info f  where f.user_account  = #{userAccount}")
    String selectUniscIdByAccount(@Param("userAccount") String userAccount);

    @Select("select address from  farmer_user_info f  where f.user_account  = #{userAccount}")
    String selectAssressByAccount(@Param("userAccount") String userAccount);

    @Select("select count(0) from  farmer_user_info f  where f.business  = #{uniscId}")
    int selectCountUser(@Param("uniscId")String uniscId);
}

